Skip to content

anchor wildcard virtual host match in VirtualHostRuleContainer - #16206

Open
Bhav-ya-H wants to merge 1 commit into
jetty:jetty-12.1.xfrom
Bhav-ya-H:rewrite-wildcard-vhost-anchor
Open

Bhav-ya-H wants to merge 1 commit into
jetty:jetty-12.1.xfrom
Bhav-ya-H:rewrite-wildcard-vhost-anchor

Conversation

@Bhav-ya-H

Copy link
Copy Markdown
Contributor

VirtualHostRuleContainer scopes the rules it groups to a configured set of virtual hosts, and for a *.foo.com entry it compares the configured domain with the part of the request server name that follows the first dot. The comparison is a String.regionMatches over the length of the configured domain, so it checks only that the server name starts with that domain at that offset, never that it ends there. Host: vhost.foo.com.evil.com and Host: vhost.foo.comevil.com both match *.foo.com, so every rule in the container runs for a host the deployment never configured, which matters when those rules rewrite paths, force request headers or set response headers for one tenant only. ContextHandler.VHost.matches already anchors its wildcard comparison at the end of the host name and limits the wildcard to one label, so the fix is to make the rewrite container agree with it and require the name after the first dot to be exactly the configured domain. The null check keeps the wildcard branch from throwing when a request carries no authority, which the old serverName.indexOf(".") call did. I found it while comparing the two wildcard host matchers; the vectors added to testWildcardVirtualHosts fail before the change, and the jetty-rewrite suite (211 tests) and checkstyle are green after it.

Signed-off-by: Bhavya H <bhavya@labs.digiscrypt.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant